<template>
	<view>
		<view class="list">
			<view class="phone" v-for="(item,index) in list" :key="index">
				<view class="item">
					<view class="label">
						合作客户：
					</view>
					<view class="value">
						{{item.org}}
					</view>
				</view>
				<view class="item">
					<view class="label">
						二维码：
					</view>
					<view class="value">
						<image class="code" :src="item.img" mode="widthFix"></image>
					</view>
				</view>
				<view class="operate">
					<view class="btn" type="primary" @click="downLoad(item)">查看二维码</view>
				</view>
			</view>
		</view>
		<u-empty v-if="list.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/car.png">
		</u-empty>
		<u-modal v-model="show" title="登录" @confirm="confirmModal" :show-cancel-button="true" cancel-text="取消"
			confirm-text="登录" @cancel="cancel">
			<login ref="login"></login>
		</u-modal>
	</view>
</template>

<script>
	import {
		customerListApi
	} from "@/api/index.js"
	import login from "./simulationLogin.vue"
	export default {
		components: {
			login
		},
		data() {
			return {
				show: false,
				list: [],
				page: 1,
				finish: false,
				tabIndex: 0,
				status: 0,
				studentList: [],
				mobile: ''
			};
		},
		onShow() {
			let mobile = uni.getStorageSync("yPhone")
			if (mobile) {
				this.mobile = mobile
				this.getCustomerList()
			} else {
				this.show = true
			}

		},
		methods: {
			//下载
			downLoad(item) {
				uni.previewImage({
					urls: [item.img],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			//学员列表
			getCustomerList() {

				let params = {
					teacher_mobile: this.mobile,
					page: this.page,
					page_size: 200
				}
				customerListApi(params).then(res => {
					uni.stopPullDownRefresh();
					if (res.code == 1) {
						let list = res.data

						if (this.page == 1) {
							this.list = list
							this.finish = false
						} else {
							this.list = this.list.concat(list)
						}
						if (list.length < 20) {
							this.finish = true
						}
						console.log(this.list)
					}
				})
			},
			confirmModal() {
				// console.log('open');
				this.$refs.login.getGister()
			},
			cancel() {
				this.show = false
				// console.log('close');
			},
		},
		//下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.getSdutendList()

		},
		//上拉加载更多
		onReachBottom() {
			if (!this.finish) {
				this.page = this.page + 1
				this.getSdutendList()
			}

		},
	}
</script>

<style lang="scss">
	.header {
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #fff;

		.item {
			color: #606266;
			font-size: 26rpx;
			height: 80rpx;
			position: relative;
			flex: 1;
			text-align: center;
			line-height: 80rpx;
		}

		.active {
			color: #222;
		}

		.active::after {
			content: '';
			position: absolute;
			bottom: 0;
			left: 50%;
			margin-left: -15px;
			width: 30px;
			height: 2px;
			background-color: #2979ff;
			border-radius: 10px;
		}
	}

	.list {

		margin-top: 20rpx;
		padding: 0 26rpx;

		.phone {
			background-color: #fff;
			padding: 26rpx;
			border-radius: 10rpx;

			.item {
				color: #969696;
				font-size: 28rpx;
				font-weight: 400;
				margin-top: 10rpx;
				display: flex;


				.label {
					width: 150rpx;
					color: #666;
				}

				.value {
					color: #333;

					.code {
						width: 50rpx;
					}
				}
			}

			.operate {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				margin-top: 20rpx;

				.btn {
					background-color: #2979ff;
					margin-left: 20rpx;
					line-height: 60rpx;
					color: #fff;
					width: 200rpx;
					text-align: center;
					border-radius: 6rpx;
					font-size: 26rpx;
				}
			}
		}
	}
</style>